package com.wqiuqiu.gulimall.ware.listener;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rabbitmq.client.Channel;
import com.wqiuqiu.gulimall.ware.service.WareOrderTaskService;
import com.wqiuqiu.gulimall.ware.service.WareSkuService;
import com.wqiuqiu.gulimall.ware.vo.WareSkuLockVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Slf4j
@Component
public class WareListener {

    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    WareSkuService wareSkuService;



    @RabbitListener(queues = "ware.release.ware.queue")
    public void wareReleaseLitener(WareSkuLockVo vo, Channel channel, Message message) throws IOException {
        log.info("收到库存释放消息...");
        try {
            wareSkuService.unlockOrder(vo.getOrderSn());
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
        }
    }

}
